package com.bodacn.packapp.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bodacn.packapp.R;
import com.bodacn.packapp.SearchPOBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SearchPOAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private Context mContext;
    private List<SearchPOBean> list;

    public SearchPOAdapter(Context context, List<SearchPOBean> list) {
        this.inflater = LayoutInflater.from(context);
        this.mContext = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.search_po_item, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (list.size() > 0) {
            SearchPOBean searchPOBean = list.get(position);
            viewHolder.tvOrder.setText(searchPOBean.getHyh());
            viewHolder.tvGoods.setText(searchPOBean.getHh());
            viewHolder.tvPO.setText(searchPOBean.getPoh());
            viewHolder.tvYzjs.setText(searchPOBean.getPreshl());
            viewHolder.tvYzxs.setText(searchPOBean.getPreCartonNum());
            viewHolder.tvYzymxs.setText(searchPOBean.getCartonNum());
            viewHolder.tvYzwmxs.setText(searchPOBean.getHalf());
            viewHolder.tvWzxs.setText(searchPOBean.getUnCartonNum());
            viewHolder.tvXzjs.setText(searchPOBean.getUndoshl());
            if (!TextUtils.isEmpty(searchPOBean.getStatus())){
                if (searchPOBean.getStatus().equals("0")){
                    viewHolder.tvStatus.setText("未剔除");
                    viewHolder.tvStatus.setTextColor(mContext.getResources().getColor(R.color.text_green));
                }
                if (searchPOBean.getStatus().equals("1")){
                    viewHolder.tvStatus.setText("剔除");
                    viewHolder.tvStatus.setTextColor(mContext.getResources().getColor(R.color.text_red));
                }
            }

            if (searchPOBean.isCheck()) {
                viewHolder.iv.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.xuanzhong));
            } else {
                viewHolder.iv.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.weixuan));
            }

        }

        return convertView;
    }



    class ViewHolder {
        @BindView(R.id.tv_order)
        TextView tvOrder;
        @BindView(R.id.tv_goods)
        TextView tvGoods;
        @BindView(R.id.tv_PO)
        TextView tvPO;
        @BindView(R.id.tv_yzjs)
        TextView tvYzjs;
        @BindView(R.id.tv_yzxs)
        TextView tvYzxs;
        @BindView(R.id.tv_yzymxs)
        TextView tvYzymxs;
        @BindView(R.id.tv_yzwmxs)
        TextView tvYzwmxs;
        @BindView(R.id.tv_wzxs)
        TextView tvWzxs;
        @BindView(R.id.tv_xzjs)
        TextView tvXzjs;
        @BindView(R.id.tv_status)
        TextView tvStatus;
        @BindView(R.id.iv)
        ImageView iv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
